<template>
  <div class="salesmansList">
    <div class="serchContent">
      <el-input v-model="input" placeholder="请输入内容"></el-input>
    </div>
    <div class="add">
      <el-button @click="add">新增</el-button>
    </div>
    <el-table :data='salesmansList' border style="width: 100%">
      <el-table-column prop="username" label="账号"> </el-table-column>
      <el-table-column prop="name" label="姓名"> </el-table-column>
      <el-table-column prop="sex" label="性别"> </el-table-column>
      <el-table-column prop="age" label="年龄"> </el-table-column>
      <el-table-column prop="tel" label="联系方式"> </el-table-column>
      <el-table-column prop="images" label="头像" width="100px">
         <template slot-scope="scope">
         
          <img
            style="margin-left: 10px"
            :src="'http://localhost:3000/temp/' + scope.row.images"
            class="salesmansImg"
          />
        </template>
      </el-table-column>
      <el-table-column  label="操作">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.$index, scope.row)"
            >编辑</el-button
          >
          <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.$index, scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { createNamespacedHelpers } from "vuex";
const { mapActions } = createNamespacedHelpers("salesmans");
export default {
  data() {
    return {
      input: "",
      salesmansList: [{}],
    };
  },
  methods: {
    ...mapActions(["getSalesmansData","getSalesmansDeleteById"]),
    handleEdit(index, row) {
       this.$router.push(`/System/salesmansModify/${row._id}`);
    },
   async handleDelete(index, row) {
      this.getSalesmansDeleteById({_id:row._id});
      this.salesmansList = await this.getSalesmansData({ val: this.input });
      
    },
    //新增跳转
    add() {
      this.$router.push("/System/SalesmansAdd");
    },
  },
  async created() {
    this.salesmansList = await this.getSalesmansData({ val: this.input });
  },
  watch: {
    async input(val) {
      this.salesmansList = await this.getSalesmansData({ val });
    },
  },
};
</script>

<style lang="scss" >
.salesmansList {
  position: relative;
}
.salesmansList .serchContent .el-input {
  width: 15% !important;
}
.salesmansList .add {
  position: absolute;
  top: 0px;
  left: 800px;
}
.salesmansList .el-table {
  margin-top: 30px;
}
.salesmansList .salesmansImg {
  width: 60px;
  height: 60px;
}
</style>